package fei.zhou.springboot2.exception;

import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

/**
 * 描述该类- JPA
 *
 * @author zhoufei
 * @class: MyErrorAttributes
 * @date 2021/1/13  19:54
 * @Verson 1.0 -2021/1/13  19:54
 * @see
 */
//给容器中加入我们自己定义的ErrorAttributes
@Component
public class MyErrorAttributes extends DefaultErrorAttributes {
    @Override
    //返回值的map就是页面和json能获取的所有字段
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {

        Map<String, Object> map = super.getErrorAttributes(webRequest, includeStackTrace);
        map.put("message1","message1");
        map.put("message2","message2");
        map.put("message3","message3");

        //我们的异常处理器携带的数据
        Map<String,Object> ext = (Map<String, Object>) webRequest.getAttribute("ext", 0);
        map.put("ext",ext);
        return map;

    }


}